package com.lianniu.web.product.service.impl;
 import java.util.List;
 import java.util.Map;
 import java.util.ArrayList;
 import com.alibaba.fastjson.JSON;
import java.util.HashMap;
 import org.springframework.beans.factory.annotation.Autowired;
 import com.lianniu.web.base.BaseResult;
 import com.lianniu.web.constants.ErrorCode;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Service;
 import com.lianniu.web.util.StringUtil;
 import com.lianniu.web.pagination.PaginationInfo;
import com.lianniu.web.product.model.ProductpicVo;
 import com.lianniu.web.product.service.IProductpicService;
 import com.lianniu.web.product.dao.IProductpicDao;


/**
 * 
 * Productpic数据库操作接口类实现
 * 
 **/

	 @Service
public class ProductpicServiceImpl implements IProductpicService{
	 private final static Logger logger = Logger.getLogger(ProductpicServiceImpl.class);
	 @Autowired
	  IProductpicDao ProductpicDao;

	/**
	 * 
	 * 查询(根据主键ID查询)
	 * 
	 **/
	 @Override
	 public BaseResult selectById (ProductpicVo record ){
	 logger.info("selectById begin.");
	 logger.info("selectById Id:" +record.getPicId());
		 if(record.getPicId()==null){
			 return BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
		 }
		 return BaseResult.success(ProductpicDao.selectById(record.getPicId()));   
	} 

	/**
	 * 
	 * 删除(根据主键ID删除)
	 * 
	 **/
	 @Override
	 public BaseResult deleteProductpicBatch (String... id ){
		 logger.info("deleteProductpicBatch begin");
		 logger.info("deleteProductpicBatch Ids:"+id.toString());
		 logger.info("deleteProductpicBatch: input data check begin");
		  BaseResult baseResult;
		  if (StringUtil.isEmpty(id.toString())) {
		   baseResult =  BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
		   return baseResult;
		 }
		 logger.info("deleteProductpicBatch: input data check end");
		 return BaseResult.success(ProductpicDao. deleteProductpicBatch (id));   
	} 

	/**
	 * 
	 * 添加
	 * 
	 **/
	 @Override
	 public BaseResult insertProductpic( ProductpicVo record ){
			 logger.info("insertProductpic begin");
			  logger.info("insertProductpic: input data check begin");
			 logger.info("insertProductpic record:" +JSON.toJSONString(record));
			 logger.info("insertProductpic end");
			 return BaseResult.success(ProductpicDao.insertProductpic(record));

	} 

	/**
	 * 
	 * 修改
	 * 
	 **/
	 @Override
	 public BaseResult UpdateById( ProductpicVo record ){
			 logger.info("updateById begin");
			 logger.info("updateById: update data check begin");
			 logger.info("updateById record:" +JSON.toJSONString(record));
		 if(record.getPicId()!=null){
			 return BaseResult.success(ProductpicDao.updateById(record));

	} 
			 return BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
	} 

	/**
	 * 
	 *  查询一个分页列表
	 * 
	 **/
	 @Override
	 public  BaseResult selectByProductpicForPage( ProductpicVo record,PaginationInfo paginationInfo ){
			 logger.info("selectByProductpicForPage begin.");
			 record.setPaginationInfo(paginationInfo);
		  List<ProductpicVo> list=ProductpicDao.selectByProductpicForPage(record); 
		  Map<String,Object> retmap=new HashMap<String,Object>(); 
		  retmap.put("total", paginationInfo.getTotalRecord()); 
		  retmap.put("curPage", paginationInfo.getCurPage()); 
		  retmap.put("rows", list);
		  logger.info("selectByProductpicForPage:  end");
		  return BaseResult.success(retmap); 
	}

    @Override
    public BaseResult selectPicByProductId(String productId) {
      logger.info("selectByProductId begin");
        return BaseResult.success(ProductpicDao.selectByProductId(productId));
    }

}